package com.daekwang.action;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.daekwang.domain.Result;
import com.daekwang.domain.WriteVO;
import com.daekwang.service.WriteService;
import com.google.gson.Gson;

@Controller
public class WriteAction {
	
	static Logger logger = Logger.getLogger(WriteAction.class);
	
	private WriteService service;
	
	public void setService(WriteService service) {
		this.service = service;
	}
	
	@RequestMapping(value = "write.action", params = "method=writeContent") 
	@ResponseBody
	public String writeContent(WriteVO vo) {
		if(vo.getPrivacy() != null) {
			vo.setPrivacy("1");
		} else {
			vo.setPrivacy("0");
		}
		
		int number = service.writeContent(vo);
		
		String result = "";
		if(number == 1) {
			result = "<script>alert('success'); window.close(); parent.history.go(-2);</script>";
		} else {
			result = "<script>alert('fail'); window.close(); parent.history.go(-1);</script>";
		}
		
		return result;
	}
}
